<?php
    if (!defined('EXPONENT')) exit('');
    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate"),$loc))
    {
        $id=0;
        if (isset($_REQUEST['id']))
            $id=intval($_REQUEST['id']);
        
        $template=new template("mailsystemmodule","_template_manage_edit",$loc);        
        $content=$db->selectObject('mailsystem_template','id='.$id);
               
        if (!$content)
        {
            //set default
            $content->name='';
            $content->dir='';
            $content->description='';
            $content->group='default';
            $content->content='';
            $content->support_file=0;
            $content->support_param=0;
            $content->date=time();            
        }
        
        //Create form
        if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
        exponent_forms_initialize();
        $form = new form();
        $form->meta('id',$content->id);
        $form->meta('module','mailsystemmodule');
        $form->meta('action','templates_manage_save');        
        $form->register('_temp_name','Name',new textcontrol($content->name));
        $form->register('_temp_dir','Dir',new textcontrol($content->dir));
        $form->register('_temp_group','Group',new textcontrol($content->group));
        $form->register('_temp_description','Description',new textcontrol($content->description));
        $html="Parameter you can insert: <br>%name%";
        $form->register('_param','Parameter',new htmlcontrol($html));
        $form->register('_temp_content','Content',new htmleditorcontrol($content->content)); 
        $form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
              
        $template->assign('form',$form->toHTML());
        $template->register_permissions(array('administrate',"configure"),$loc);
        $template->output();
    }
    else
    {
        exponent_http_error(403);
    }
?>
